﻿function showContestRanklist(cid, pn) {
	if (refreshTab('showContestRanklist'))
		return;
	var ps = [];
	for (var i = 0; i < pn; ++i) {
		var str = 'A';
		var k = str.charCodeAt(0);
		k += i;
		var nstr = String.fromCharCode(k);
		ps.push(nstr);
	}
	var storeArr = ['rank', 'username', 'ac', 'usetime'].concat(ps);
	for(var i = 0;i<pn;++i)
	{
		storeArr.push(ps[i] + '_ac');
		storeArr.push(ps[i] + '_submit');
	}
	var store = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({
							url : url.showContestRanklist
						}),
				reader : new Ext.data.JsonReader({
							root : 'result',
							totalProperty : 'total',
							id : 'username'
						}, storeArr)
			});

	store.load({
				params : {
					cid : cid
				}
			})
	var cmArr = [{
				header : 'Rank',
				sortable : false,
				dataIndex : 'rank',
				width : 100
			}, {
				header : 'Player',
				sortable : false,
				dataIndex : 'username',
				width : 100
			}];

	for (var i = 0; i < pn; ++i) {
		cmArr.push({
					header : ps[i],
					sortable : false,
					dataIndex : ps[i],
					renderer : solveRender
				})
	}
	function solveRender(value, p, record) {
		return String.format("{0}/{1}", record.data[value + "_ac"],
				record.data[value + "_submit"]);
	}
	cmArr.push({
				header : "accept",
				sortable : false,
				dataIndex : 'ac',
				width : 100
			}, {
				header : 'Time',
				sortable : false,
				dataIndex : 'usetime',
				width : 100
			});
	var cm = new Ext.grid.ColumnModel(cmArr);

	var grid = new Ext.grid.GridPanel({// 面板主控件
		id : 'showContestRanklist',
		title : 'Ranklist',
		closable : true,
		region : 'center',
		loadMask : {
			msg : '载入中...'
		},
		viewConfig : {
			forceFit : true
		},
		store : store,
		cm : cm
	});
	addTab(grid);
}